home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The SelectWare System Volume 5 #4
/
The SelectWare System Volume 5 #4.iso
/
bor10012
/
rtsmp.pak
/
OVLOOPS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-06-10
|
6KB
|
172 lines
// Borland ObjectVision -- (C) Copyright 1991,1992 by Borland International
/*
Build OVLOOPS.DLL with a command such as this:
icc /Ge- /Gm+ /Ss+ ovloops.c ovloops.def
*/
#include <os2.h>
#include <string.h>
typedef PCHAR APIENTRY OVCALLBACK_GET ( PCHAR );
typedef void APIENTRY OVCALLBACK_PUT ( PCHAR, PCHAR );
typedef PCHAR APIENTRY OVCALLBACK_EXECUTESTRING ( PCHAR, PCHAR, unsigned,
unsigned );
/******************************************************************************
*
* name SelfRegister -- Register all of the functions of this DLL
*
* arguments 1. OVCALLBACK_EXECUTESTRING lpfnCallBack -- callback fn
*
* return Zero
*
* register @REGISTER("@REGISTER_OVLOOPS","In","","ovloops.dll",
* "SelfRegister",1)
*
******************************************************************************/
int EXPENTRY SelfRegister( OVCALLBACK_EXECUTESTRING lpfnCallBack )
{
(void)(*lpfnCallBack)(
"@REGISTER(\"@WHILELOOP\",\"ICCn\",\"\"\"ConditionExpression\"\","
"\"\"ActionExpression\"\"\",\"ovloops.dll\",\"iWhileLoop\",1)"
, 0, 0, 0 );
(void)(*lpfnCallBack)(
"@REGISTER(\"@WHILEFIELD\",\"JCCwx\",\"\"\"ConditionField\"\","
"\"\"EventField\"\"\",\"ovloops.dll\",\"lWhileField\",1)"
, 0, 0, 0 );
(void)(*lpfnCallBack)(
"@REGISTER(\"@EXECUTE\",\"CCnF\",\"\"\"CommandToExecute\"\"\","
"\"ovloops.dll\",\"szExecuteString\",1)"
, 0, 0, 0 );
return 0;
}
/******************************************************************************
*
* name iWhileLoop -- While function using ExecuteString callback
*
* description You can use this function to implement an @WHILELOOP in OV.
* Link error reporting is disabled during both condition and
* action execution.
*
* arguments 1. PCHAR szCondition -- the condition expression
* 2. PCHAR szAction -- the action expression
* 3. OVCALLBACK_EXECUTESTRING lpfnCallBack -- callback fn
*
* return Zero (an int)
*
* register @REGISTER("@WHILELOOP","ICCn",
* """ConditionExpression"",""ActionExpression""",
* "ovloops.dll","iWhileLoop",1)
*
******************************************************************************/
int EXPENTRY iWhileLoop(
PCHAR szCondition,
PCHAR szAction,
OVCALLBACK_EXECUTESTRING lpfnCallBack )
{
char sBuf[10];
char * szConditionResult;
szConditionResult = (*lpfnCallBack)( szCondition, sBuf, sizeof(sBuf), 1 );
while ( szConditionResult && !strcmp(szConditionResult,"Yes") )
{
(void)(*lpfnCallBack)( szAction, (PCHAR)0, 0, 1 );
szConditionResult = (*lpfnCallBack)( szCondition, sBuf,
sizeof(sBuf), 1 );
}
return 0;
}
/******************************************************************************
*
* name lWhileField -- While function using only Get & Put callbacks
*
* description You can use this function to implement an @WHILEFIELD in OV.
*
* arguments 1. PCHAR szConditionField
* 2. PCHAR szEventField
* 3. OVCALLBACK_PUT lpfnPutCallBack
* 4. OVCALLBACK_GET lpfnGetCallBack
*
* return unsigned long -- the number of times through the loop
*
* register @REGISTER("@WHILEFIELD","JCCwx","""ConditionField"",
* ""EventField""","ovloops.dll","lWhileField",1)
*
******************************************************************************/
unsigned long EXPENTRY lWhileField(
PCHAR szConditionField,
PCHAR szEventField,
OVCALLBACK_PUT lpfnPutCallBack,
OVCALLBACK_GET lpfnGetCallBack )
{
char * szCondition;
char * szEvent;
char sNumber[20];
unsigned long lLoop;
szCondition = (*lpfnGetCallBack)( szConditionField );
szEvent = (*lpfnGetCallBack)( szEventField );
if ( szCondition == 0 || szEvent == 0 )
{
// One of the fields doesn't exists. Don't event try because
// the while would loop forever.
lLoop = 0;
}
else
{
lLoop = 0;
while ( strcmp(szCondition,"No") )
{
lLoop++;
sprintf(sNumber,"%ld",lLoop);
if ( lLoop == 1 && !strcmp(szEvent,sNumber) )
{
strcpy( sNumber, "0" ); // To ensure we get a change event
}
(*lpfnPutCallBack)( (PCHAR)szEventField, (PCHAR)sNumber );
szCondition = (*lpfnGetCallBack)( szConditionField );
}
}
return lLoop;
}
/******************************************************************************
*
* name szExecuteString -- Send a command string to OV for execution
*
* description Use this function to send a command to OV for execution.
*
* arguments 1. PCHAR szCommand -- the command to execute
* 2. OVCALLBACK_EXECUTESTRING lpfnCallBack -- callback fn
* 3. PCHAR sAnswerBuffer -- place for the answer
*
* return PCHAR -- result string
*
* register @REGISTER("@EXECUTE","CCnF","""CommandToExecute""",
* "ovloops.dll","szExecuteString",1)
*
******************************************************************************/
PCHAR EXPENTRY szExecuteString(
PCHAR szCommand,
OVCALLBACK_EXECUTESTRING lpfnCallBack,
PCHAR sAnswerBuf )
{
PCHAR szResult;
szResult = (*lpfnCallBack)( szCommand, sAnswerBuf, 4096, 0 );
if ( !szResult )
{
szResult = ""; // Return something
}
return szResult;
}